package com.hd123.rumba.gwt.widget2.client.action;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.ClickListener;
import com.hd123.rumba.gwt.util.client.GWTUtil;
import com.hd123.rumba.gwt.widget2.client.hotkey.RHotKey;
import com.hd123.rumba.gwt.widget2.client.hotkey.RKey;
import com.hd123.rumba.gwt.widget2.client.misc.RImageLocation;

/**
 * 常用的RAction工厂
 * 
 * @author LiQi
 * 
 */
@SuppressWarnings("deprecation")
public class RActionFactory {

  public static final String VIEW_CAPTION = "查看";
  public static final String VIEW_ICON = "rumba/images/3/widget/toolbar/view_small.gif";
  public static final String VIEW_ICON_DISABLED = "rumba/images/3/widget/toolbar/view_small_dis.gif";
  public static final RHotKey VIEW_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_V);

  public static final String CREATE_CAPTION = "新增";
  public static final String CREATE_ICON = "rumba/images/3/widget/toolbar/create_small.gif";
  public static final String CREATE_ICON_DISABLED = "rumba/images/3/widget/toolbar/create_small_dis.gif";
  public static final RHotKey CREATE_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_N);

  public static final String EDIT_CAPTION = "编辑";
  public static final String EDIT_ICON = "rumba/images/3/widget/toolbar/edit_small.gif";
  public static final String EDIT_ICON_DISABLED = "rumba/images/3/widget/toolbar/edit_small_dis.gif";
  public static final RHotKey EDIT_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_E);

  public static final String SAVE_CAPTION = "保存";
  public static final String SAVE_ICON = "rumba/images/3/widget/toolbar/save_small.gif";
  public static final String SAVE_ICON_DISABLED = "rumba/images/3/widget/toolbar/save_small_dis.gif";
  public static final RHotKey SAVE_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_S);

  public static final String CANCEL_CAPTION = "取消";
  public static final String CANCEL_ICON = "rumba/images/3/widget/toolbar/cancel_small.gif";
  public static final String CANCEL_ICON_DISABLED = "rumba/images/3/widget/toolbar/cancel_small_dis.gif";

  public static final String RESET_CAPTION = "重置";
  public static final String RESET_ICON = "rumba/images/3/widget/toolbar/reset_small.gif";
  public static final String RESET_ICON_DISABLED = "rumba/images/3/widget/toolbar/reset_small_dis.gif";

  public static final String LIST_CAPTION = "列表";
  public static final String LIST_ICON = "rumba/images/3/widget/toolbar/back_small.gif";
  public static final String LIST_ICON_DISABLED = "rumba/images/3/widget/toolbar/back_small_dis.gif";
  public static final RHotKey LIST_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_X);

  public static final String RECYCLE_CAPTION = "回收站";
  public static final String RECYCLE_ICON = "rumba/images/3/widget/general/recycle_small.gif";
  public static final String RECYCLE_ICON_DISABLED = "rumba/images/3/widget/general/recycle_small_dis.gif";

  public static final String UNDELETE_CAPTION = "恢复";
  public static final String UNDELETE_ICON = "rumba/images/3/widget/toolbar/undelete_small.gif";
  public static final String UNDELETE_ICON_DISABLED = "rumba/images/3/widget/toolbar/undelete_small_dis.gif";
  public static final RHotKey UNDELETE_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_R);

  public static final String DELETE_CAPTION = "删除";
  public static final String DELETE_ICON = "rumba/images/3/widget/toolbar/delete_small.gif";
  public static final String DELETE_ICON_DISABLED = "rumba/images/3/widget/toolbar/delete_small_dis.gif";
  public static final RHotKey DELETE_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_D);

  public static final String OK_CAPTION = "确认";
  public static final String OK_ICON = "rumba/images/3/widget/toolbar/ok_small.gif";
  public static final String OK_ICON_DISABLED = "rumba/images/3/widget/toolbar/ok_small_dis.gif";

  public static final String VIEWLOG_CAPTION = "查看日志";
  public static final String VIEWLOG_ICON = "rumba/images/3/widget/toolbar/entitylog_small.gif";
  public static final String VIEWLOG_ICON_DISABLED = "rumba/images/3/widget/toolbar/entitylog_small_dis.gif";

  public static final String OPEN_CAPTION = "打开";
  public static final String OPEN_ICON = "rumba/images/3/widget/toolbar/open_small.gif";
  public static final String OPEN_ICON_DISABLED = "rumba/images/3/widget/toolbar/open_small_dis.gif";
  public static final RHotKey OPEN_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_O);

  public static final String LAST_CAPTION = "上一步";
  public static final String LAST_ICON = "rumba/images/3/widget/toolbar/last_small.gif";
  public static final String LAST_ICON_DISABLED = "rumba/images/3/widget/toolbar/last_small_dis.gif";
  public static final RHotKey LAST_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_L);

  public static final String NEXT_CAPTION = "下一步";
  public static final String NEXT_ICON = "rumba/images/3/widget/toolbar/next_small.gif";
  public static final String NEXT_ICON_DISABLED = "rumba/images/3/widget/toolbar/next_small_dis.gif";
  public static final RHotKey NEXT_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_T);

  public static final String UP_CAPTION = "上一级";
  public static final String UP_ICON = "rumba/images/3/widget/toolbar/up_small.gif";
  public static final String UP_ICON_DISABLED = "rumba/images/3/widget/toolbar/up_small_dis.gif";
  public static final RHotKey UP_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_U);

  public static final String FILTER_CAPTION = "筛选";
  public static final String FILTER_ICON = "rumba/images/3/widget/toolbar/filter_small.gif";
  public static final String FILTER_ICON_DISABLED = "rumba/images/3/widget/toolbar/filter_small_dis.gif";
  public static final RHotKey FILTER_HOTKEY = new RHotKey(false, true, false, RKey.KEY_CODE_F);

  public static final String REFRESH_CAPTION = "刷新";
  public static final String REFRESH_ICON = "rumba/images/3/widget/toolbar/refresh_small.gif";
  public static final String REFRESH_ICON_DISABLED = "rumba/images/3/widget/toolbar/refresh_small_dis.gif";

  /**
   * @deprecated 被
   *             {@link #makeAction(String, String, String, ClickHandler)}
   *             替代。
   */
  public static RAction makeAction(String caption, String icon, String disabledIcon,
      RHotKey hotKey, ClickListener listener) {
    RAction action = new RAction();
    action.setCaption(caption);
    action.setIcon(new RImageLocation(GWTUtil.getStaticContentURL(icon)));
    action.setDisabledIcon(new RImageLocation(GWTUtil.getStaticContentURL(disabledIcon)));
    action.setHotKey(hotKey);
    action.addListener(listener);
    return action;
  }

  /**
   * 制造一个RAction。
   * 
   * @param caption
   * @param icon
   * @param disabledIcon
   * @param handler
   * @return
   */
  public static RAction makeAction(String caption, String icon, String disabledIcon,
      RHotKey hotKey, ClickHandler handler) {
    RAction action = new RAction();
    action.setCaption(caption);
    action.setIcon(new RImageLocation(GWTUtil.getStaticContentURL(icon)));
    action.setDisabledIcon(new RImageLocation(GWTUtil.getStaticContentURL(disabledIcon)));
    action.setHotKey(hotKey);
    action.addClickHandler(handler);
    return action;
  }

  /**
   * @deprecated 被{@link #makeViewAction(ClickHandler)}替代。
   */
  public static RAction makeViewAction(ClickListener listener) {
    return makeAction(VIEW_CAPTION, VIEW_ICON, VIEW_ICON_DISABLED, VIEW_HOTKEY, listener);
  }

  /**
   * 查看
   * 
   * @param handler
   * @return
   */
  public static RAction makeViewAction(ClickHandler handler) {
    return makeAction(VIEW_CAPTION, VIEW_ICON, VIEW_ICON_DISABLED, VIEW_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeCreateAction(ClickHandler)}替代。
   */
  public static RAction makeCreateAction(ClickListener listener) {
    return makeAction(CREATE_CAPTION, CREATE_ICON, CREATE_ICON_DISABLED, CREATE_HOTKEY, listener);
  }

  /**
   * 新增
   * 
   * @param handler
   * @return
   */
  public static RAction makeCreateAction(ClickHandler handler) {
    return makeAction(CREATE_CAPTION, CREATE_ICON, CREATE_ICON_DISABLED, CREATE_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeEditAction(ClickHandler)}替代。
   */
  public static RAction makeEditAction(ClickListener listener) {
    return makeAction(EDIT_CAPTION, EDIT_ICON, EDIT_ICON_DISABLED, EDIT_HOTKEY, listener);
  }

  /**
   * 编辑
   * 
   * @param handler
   * @return
   */
  public static RAction makeEditAction(ClickHandler handler) {
    return makeAction(EDIT_CAPTION, EDIT_ICON, EDIT_ICON_DISABLED, EDIT_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeSaveAction(ClickHandler)}替代。
   */
  public static RAction makeSaveAction(ClickListener listener) {
    return makeAction(SAVE_CAPTION, SAVE_ICON, SAVE_ICON_DISABLED, SAVE_HOTKEY, listener);
  }

  /**
   * 保存
   * 
   * @param handler
   * @return
   */
  public static RAction makeSaveAction(ClickHandler handler) {
    return makeAction(SAVE_CAPTION, SAVE_ICON, SAVE_ICON_DISABLED, SAVE_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeCancelAction(ClickHandler)}替代。
   */
  public static RAction makeCancelAction(ClickListener listener) {
    return makeAction(CANCEL_CAPTION, CANCEL_ICON, CANCEL_ICON_DISABLED, null, listener);
  }

  /**
   * 取消
   * 
   * @param handler
   * @return
   */
  public static RAction makeCancelAction(ClickHandler handler) {
    return makeAction(CANCEL_CAPTION, CANCEL_ICON, CANCEL_ICON_DISABLED, null, handler);
  }

  /**
   * 取消
   * 
   * @param listener
   * @return
   */
  public static RAction makeCancelAction() {
    return makeAction(CANCEL_CAPTION, CANCEL_ICON, CANCEL_ICON_DISABLED, null, new ClickHandler() {
      public void onClick(ClickEvent event) {
        History.back();
      }
    });
  }

  /**
   * @deprecated 被{@link #makeResetAction(ClickHandler)}替代。
   */
  public static RAction makeResetAction(ClickListener listener) {
    return makeAction(RESET_CAPTION, RESET_ICON, RESET_ICON_DISABLED, null, listener);
  }

  /**
   * 重置
   * 
   * @param handler
   * @return
   */
  public static RAction makeResetAction(ClickHandler handler) {
    return makeAction(RESET_CAPTION, RESET_ICON, RESET_ICON_DISABLED, null, handler);
  }

  /**
   * @deprecated 被{@link #makeListAction(ClickHandler)}替代。
   */
  public static RAction makeListAction(ClickListener listener) {
    return makeAction(LIST_CAPTION, LIST_ICON, LIST_ICON_DISABLED, LIST_HOTKEY, listener);
  }

  /**
   * 列表
   * 
   * @param handler
   * @return
   */
  public static RAction makeListAction(ClickHandler handler) {
    return makeAction(LIST_CAPTION, LIST_ICON, LIST_ICON_DISABLED, LIST_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeRecycleAction(ClickHandler)}替代。
   */
  public static RAction makeRecycleAction(ClickListener listener) {
    return makeAction(RECYCLE_CAPTION, RECYCLE_ICON, RECYCLE_ICON_DISABLED, null, listener);
  }

  /**
   * 回收站
   * 
   * @param handler
   * @return
   */
  public static RAction makeRecycleAction(ClickHandler handler) {
    return makeAction(RECYCLE_CAPTION, RECYCLE_ICON, RECYCLE_ICON_DISABLED, null, handler);
  }

  /**
   * @deprecated 被{@link #makeUndeleteAction(ClickHandler)}替代。
   */
  public static RAction makeUndeleteAction(ClickListener listener) {
    return makeAction(UNDELETE_CAPTION, UNDELETE_ICON, UNDELETE_ICON_DISABLED, UNDELETE_HOTKEY,
        listener);
  }

  /**
   * 恢复
   * 
   * @param handler
   * @return
   */
  public static RAction makeUndeleteAction(ClickHandler handler) {
    return makeAction(UNDELETE_CAPTION, UNDELETE_ICON, UNDELETE_ICON_DISABLED, UNDELETE_HOTKEY,
        handler);
  }

  /**
   * @deprecated 被{@link #makeDeleteAction(ClickHandler)}替代。
   */
  public static RAction makeDeleteAction(ClickListener listener) {
    return makeAction(DELETE_CAPTION, DELETE_ICON, DELETE_ICON_DISABLED, DELETE_HOTKEY, listener);
  }

  /**
   * 删除
   * 
   * @param handler
   * @return
   */
  public static RAction makeDeleteAction(ClickHandler handler) {
    return makeAction(DELETE_CAPTION, DELETE_ICON, DELETE_ICON_DISABLED, DELETE_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeOkAction(ClickHandler)}替代。
   */
  public static RAction makeOkAction(ClickListener listener) {
    return makeAction(OK_CAPTION, OK_ICON, OK_ICON_DISABLED, null, listener);
  }

  /**
   * 确认
   * 
   * @param handler
   * @return
   */
  public static RAction makeOkAction(ClickHandler handler) {
    return makeAction(OK_CAPTION, OK_ICON, OK_ICON_DISABLED, null, handler);
  }

  /**
   * @deprecated 被{@link #makeViewlogAction(ClickHandler)替代。
   */
  public static RAction makeViewlogAction(ClickListener listener) {
    return makeAction(VIEWLOG_CAPTION, VIEWLOG_ICON, VIEWLOG_ICON_DISABLED, null, listener);
  }

  /**
   * 查看日志
   * 
   * @param handler
   * @return
   */
  public static RAction makeViewlogAction(ClickHandler handler) {
    return makeAction(VIEWLOG_CAPTION, VIEWLOG_ICON, VIEWLOG_ICON_DISABLED, null, handler);
  }

  /**
   * @deprecated 被{@link #makeOpenAction(ClickHandler)}替代。
   */
  public static RAction makeOpenAction(ClickListener listener) {
    return makeAction(OPEN_CAPTION, OPEN_ICON, OPEN_ICON_DISABLED, OPEN_HOTKEY, listener);
  }

  /**
   * 打开
   * 
   * @param handler
   * @return
   */
  public static RAction makeOpenAction(ClickHandler handler) {
    return makeAction(OPEN_CAPTION, OPEN_ICON, OPEN_ICON_DISABLED, OPEN_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeLastAction(ClickHandler)}替代。
   */
  public static RAction makeLastAction(ClickListener listener) {
    return makeAction(LAST_CAPTION, LAST_ICON, LAST_ICON_DISABLED, LAST_HOTKEY, listener);
  }

  /**
   * 上一步
   * 
   * @param handler
   * @return
   */
  public static RAction makeLastAction(ClickHandler handler) {
    return makeAction(LAST_CAPTION, LAST_ICON, LAST_ICON_DISABLED, LAST_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeNextAction(ClickHandler)}替代。
   */
  public static RAction makeNextAction(ClickListener listener) {
    return makeAction(NEXT_CAPTION, NEXT_ICON, NEXT_ICON_DISABLED, NEXT_HOTKEY, listener);
  }

  /**
   * 下一步
   * 
   * @param handler
   * @return
   */
  public static RAction makeNextAction(ClickHandler handler) {
    return makeAction(NEXT_CAPTION, NEXT_ICON, NEXT_ICON_DISABLED, NEXT_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeUpAction(ClickHandler)}替代。
   */
  public static RAction makeUpAction(ClickListener listener) {
    return makeAction(UP_CAPTION, UP_ICON, UP_ICON_DISABLED, UP_HOTKEY, listener);
  }

  /**
   * 上一级
   * 
   * @param handler
   * @return
   */
  public static RAction makeUpAction(ClickHandler handler) {
    return makeAction(UP_CAPTION, UP_ICON, UP_ICON_DISABLED, UP_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeFilterAction(ClickHandler)}替代。
   */
  public static RAction makeFilterAction(ClickListener listener) {
    return makeAction(FILTER_CAPTION, FILTER_ICON, FILTER_ICON_DISABLED, FILTER_HOTKEY, listener);
  }

  /**
   * 筛选
   * 
   * @param handler
   * @return
   */
  public static RAction makeFilterAction(ClickHandler handler) {
    return makeAction(FILTER_CAPTION, FILTER_ICON, FILTER_ICON_DISABLED, FILTER_HOTKEY, handler);
  }

  /**
   * @deprecated 被{@link #makeRefreshAction(ClickHandler)}替代。
   */
  public static RAction makeRefreshAction(ClickListener listener) {
    return makeAction(REFRESH_CAPTION, REFRESH_ICON, REFRESH_ICON_DISABLED, null, listener);
  }

  /**
   * 刷新
   * 
   * @param handler
   * @return
   */
  public static RAction makeRefreshAction(ClickHandler handler) {
    return makeAction(REFRESH_CAPTION, REFRESH_ICON, REFRESH_ICON_DISABLED, null, handler);
  }
}
